package viroyal.com.base.activity.engineering;

import android.os.Parcel;

import com.suntiago.baseui.activity.base.theMvp.model.IModel;
import com.suntiago.network.network.BaseRspObserver;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import viroyal.com.base.BuildConfig;
import viroyal.com.base.net.ApiObserver;
import viroyal.com.base.net.PhpApi;
import viroyal.com.base.net.req.GetSchoolIdRequest;
import viroyal.com.base.net.rsp.GetDeviceInfoResponseS;
import viroyal.com.base.net.rsp.GetSchoolListResponseS;

/**
 * author : gaochao
 * date   : 2020/3/10
 * desc   :
 */
public class DeviceInfoModel implements IModel {
  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {

  }

  private DeviceInfoModel(Parcel in) {
  }

  public DeviceInfoModel() {
  }

  public static final Creator<DeviceInfoModel> CREATOR = new Creator<DeviceInfoModel>() {
    @Override
    public DeviceInfoModel createFromParcel(Parcel in) {
      return new DeviceInfoModel(in);
    }

    @Override
    public DeviceInfoModel[] newArray(int size) {
      return new DeviceInfoModel[size];
    }
  };

  public Subscription getDeviceInfo(String deviceId, Action1<GetDeviceInfoResponseS> action1) {
    PhpApi.get().setPhpApiConfig(BuildConfig.PHP_API_HOST, "", 0);
    GetSchoolIdRequest request = new GetSchoolIdRequest(deviceId);

    return PhpApi.get().getPhpApi(ApiObserver.class)
        .getDeviceInfo(request)
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new BaseRspObserver<>(GetDeviceInfoResponseS.class, action1));
  }
}
